/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
struct Testee
{
    char registration_number[14];
    int final_rank,location_number,local_rank,score;
    //override
    bool operator<(const Testee &a) const
    {
        if (this->score!=a.score)
        {
            return this->score>a.score;
        }
        else
        {
            return strcmp(this->registration_number,a.registration_number)<0;
        }
    }
} test;
int main_1025()
{
    int N,K,num=0,idx;
    scanf("%d",&N);
    getchar();
    set<Testee> final_st,local_st;
    Testee t;
    for (int i=1; i<=N ; ++i )
    {
        scanf("%d",&K);
        getchar();
        num+=K;
        local_st.clear();
        idx=1;
        for (int j=0; j<K ; ++j)
        {
            scanf("%s %d",test.registration_number,&test.score);
            getchar();
            test.location_number=i;
            local_st.insert(test);
        }
        t=*local_st.begin();
        local_st.erase(t);
        t.local_rank=idx;
        local_st.insert(t);
        for (set<Testee>::iterator it=++local_st.begin(); it!=local_st.end() ; ++it,++idx)
        {
            Testee tn=*it;
            local_st.erase(tn);
            if (tn.score!=t.score)
            {
                tn.local_rank=idx+1;
            }
            else
            {
                tn.local_rank=t.local_rank;
            }
            t=tn;
            local_st.insert(tn);
        }
        final_st.insert(local_st.begin(),local_st.end());
    }
    idx=1;
    t=*final_st.begin();
    final_st.erase(t);
    t.final_rank=idx;
    final_st.insert(t);
    for (set<Testee>::iterator it=++final_st.begin(); it!=final_st.end() ; ++it,++idx)
    {
        Testee tn=*it;
        final_st.erase(tn);
        if (tn.score!=t.score)
        {
            tn.final_rank=idx+1;
        }
        else
        {
            tn.final_rank=t.final_rank;
        }
        t=tn;
        final_st.insert(tn);
    }
    printf("%d\n",num);
    for(Testee i:final_st)
    {
        printf("%s %d %d %d\n",i.registration_number,i.final_rank,i.location_number,i.local_rank);
    }
    return 0;
}
